<?php
include '../main/main.inc.php';
if(!$session->sesssionExists())
	die("Sessione Inesistente");


class Istance extends istance_data 
{
		
	public function __construct()
	{
		parent::__construct();
		
		switch ($_POST['op'])
		{
			case "AjaxGetAllIstanceList":
				echo $this->AjaxGetAllIstanceList();
			break;
			case "AjaxSetIstance":
				echo $this->AjaxSetIstance();
			break;
			case "AjaxDeleteIstance":
				echo $this->AjaxDeleteIstance();
			break;
			case "AjaxGetIstance":
				echo $this->AjaxGetIstance();
			break;
		}
	}
	
	public function AjaxGetAllIstanceList()
	{
		
		$Istance_data = parent::getAllIstanceList();
		/*foreach($Istance_data as $Row)
		{
			$Row = parent::getBossCountFromIstance($Row['istanceid']);
		}*/	
			
		
			
		if($Istance_data)
		{
			$elIstanzaListGrid = new elSimplyGrid();
			$elIstanzaListGrid->createSimplyGrid('Lista Istanze', 'istancelist', array('Nome Istanza', 'Abbreviazione', 'Stato Istanza', 'Numero Boss/Uccisi'), 
				$Istance_data,
				el::elButton('elimina_istanza','Elimina Istanza').el::elS().el::elButton('modifica_istanza', 'Modifica Istanza').el::elS().el::elButton('vedi_boss_istanza', 'Elenco Boss Istanza')
			);	
			return $elIstanzaListGrid->elSimplyGrid;
		}
		else
			return null;
	}
		
	public function AjaxSetIstance()
	{
		if($_POST['istancename'] != null  and $_POST['istanceshortname'] != null)
		{
				return parent::setIstance();
		}
		else
			return 'Mancano dei Campi';
	}
		
	public function AjaxDeleteIstance()
	{
		return parent::deleteIstance();
	}
		
	public function AjaxGetIstance()
	{
		return json_encode(parent::getIstance());
	}
}

if($session->sesssionExists())
		$istance = new Istance();
?>